<script setup lang="ts">
import axios   from "axios";

import {ref} from "vue";
// 定义总数据量的类型
type ChartData = {
  id: number,
  goodsId: number,
  goodsName: string,
  cost: number,
  wareHouseId: string,
  type: string,
  customerName: string,
  customerPhone: string,
  dealCount: number,
  //  交易时间
  dealTime: string,
  dealPurpose: string,
  goodsQuality: number,
  userId: number
  userName : string,
};

// 定义词云图的数据结构
type CloudChartData = {
  name: string; // 货物名称
  value: number; // 出现次数
};

// 定义饼图的数据结构
type PanChartData = {
  name: string; // 交易类型
};

// 定义金额树形图的数据结构
type MoneyTreeChartData = {
  name: string; // 货物名称
  outValue: number; // 售出总金额
  inValue: number; // 购入总金额
};

// 定义次数树形图的数据结构
type CountTreeChartData = {
  name: string; // 货物名称
  outValue: number; // 售出总次数
  inValue: number; // 购入总次数
}

//  定义地区热力图
type AreaHeatMapData = {
  type: string;//  交易类型
  area: string; // 交易区域
}
//  定义员工业绩折线图
type EmployeePerformanceChartData = {
  name: string;//  员工username
  value: number;//  负责订单的数量*0.2+订单金额*0.8
}

//  定义员工评分雷达图
type EmployeeChartData = {
  name: string;// 员工username
  count: number;//售出金额*0.7+购入金额*0.3
  quality: number;// 负责订单的货物质量
  dealCount: number;// 负责订单的数量
}
const chartData = ref<ChartData[]>()
const total = ref(0)
const outCloudChartData = ref<CloudChartData[]>([])
const inCloudChartData = ref<CloudChartData[]>([])
const transferCloudChartData = ref<CloudChartData[]>([])
const panChartData = ref<PanChartData[]>([])
const moneyTreeChartData = ref<MoneyTreeChartData[]>([])
const countTreeChartData = ref<CountTreeChartData[]>([])
const areaHeatMapData = ref<AreaHeatMapData[]>([])
const employeePerformanceChartData = ref<EmployeePerformanceChartData[]>([])
const employeeChartData = ref<EmployeeChartData[]>([])



const tempOutCloudChartData = ref<CloudChartData>(null)
const tempInCloudChartData = ref<CloudChartData>(null)
const tempTransferCloudChartData = ref<CloudChartData>(null)
const tempPanChartData = ref<PanChartData>(null)
const tempMoneyTreeChartData = ref<MoneyTreeChartData>(null)
const tempCountTreeChartData = ref<CountTreeChartData>(null)
const tempAreaHeatMapData = ref<AreaHeatMapData>(null)
const tempEmployeePerformanceChartData = ref<EmployeePerformanceChartData>(null)
const tempEmployeeChartData = ref<EmployeeChartData>(null)


function getData() {
  axios.get("http://localhost:8080/order/findAll").then(res => {
    chartData.value = res.data.data
    total.value = res.data.total
    console.log("总交易=============================")
    console.log(chartData)
    for (let Data in chartData.value) {

      //  出售
      if (chartData.value[Data].type === "售出"){
        // 出售词云
        tempOutCloudChartData.value = {
          name: chartData.value[Data].goodsName,
          value: chartData.value[Data].dealCount,
        }
        outCloudChartData.value.push(tempOutCloudChartData.value)

        //金额树形图
        tempMoneyTreeChartData.value = {
          name: chartData.value[Data].goodsName,
          outValue: chartData.value[Data].cost,
          inValue: 0,
        }
        moneyTreeChartData.value.push(tempMoneyTreeChartData.value)

        // 售出/购入量树形图
        tempCountTreeChartData.value = {
          name: chartData.value[Data].goodsName,
          outValue: chartData.value[Data].dealCount,
          inValue: 0,
        }
        countTreeChartData.value.push(tempCountTreeChartData.value)

        //地区热力图
        tempAreaHeatMapData.value = {
          type: chartData.value[Data].type,
          area: chartData.value[Data].wareHouseId
        }
        areaHeatMapData.value.push(tempAreaHeatMapData.value)

        //员工评分雷达图
        tempEmployeeChartData.value = {
          name: chartData.value[Data].userName,
          count: chartData.value[Data].cost*0.7,
          quality: chartData.value[Data].goodsQuality,
          dealCount: 1
        }
        employeeChartData.value.push(tempEmployeeChartData.value)
      }


      //  购入
      if (chartData.value[Data].type === "购入"){
        // 购入词云
        tempInCloudChartData.value = {
          name: chartData.value[Data].goodsName,
          value: chartData.value[Data].dealCount,
        }
        inCloudChartData.value.push(tempOutCloudChartData.value)


        //金额树形图
        tempMoneyTreeChartData.value = {
          name: chartData.value[Data].goodsName,
          outValue: 0,
          inValue: chartData.value[Data].cost,
        }
        moneyTreeChartData.value.push(tempMoneyTreeChartData.value)

        // 售出/购入量树形图
        tempCountTreeChartData.value = {
          name: chartData.value[Data].goodsName,
          outValue: 0,
          inValue: chartData.value[Data].dealCount
        }
        countTreeChartData.value.push(tempCountTreeChartData.value)




        //员工评分雷达图
        tempEmployeeChartData.value = {
          name: chartData.value[Data].userName,
          count: chartData.value[Data].cost*0.7,
          quality: chartData.value[Data].goodsQuality,
          dealCount: 1
        }
        employeeChartData.value.push(tempEmployeeChartData.value)
      }



      //划拨
      if (chartData.value[Data].type === "划拨"){
        //划拨词云
        tempTransferCloudChartData.value = {
          name: chartData.value[Data].goodsName,
          value: chartData.value[Data].dealCount,
        }
        transferCloudChartData.value.push(tempTransferCloudChartData.value)
      }



      //饼图
      tempPanChartData.value = {
        name: chartData.value[Data].type,
      }
      panChartData.value.push(tempPanChartData.value)

      //地区热力图
      tempAreaHeatMapData.value = {
        type: chartData.value[Data].type,
        area: chartData.value[Data].wareHouseId
      }
      areaHeatMapData.value.push(tempAreaHeatMapData.value)

      //员工业绩折线图
      tempEmployeePerformanceChartData.value = {
        name: chartData.value[Data].userName,
        value: chartData.value[Data].dealCount * 0.2 + chartData.value[Data].cost * 0.8
      }
      employeePerformanceChartData.value.push(tempEmployeePerformanceChartData.value)


    }


    console.log("出售词云=============================")
    console.log(outCloudChartData)
    console.log("购入词云=============================")
    console.log(inCloudChartData)
    console.log("划拨词云=============================")
    console.log(transferCloudChartData)
    console.log("饼图=============================")
    console.log(panChartData)
    console.log("金额树形图=============================")
    console.log(moneyTreeChartData)
    console.log("售出/购入量树形图=============================")
    console.log(countTreeChartData)
    console.log("地区热力图=============================")
    console.log(areaHeatMapData)
    console.log("员工业绩折线图=============================")
    console.log(employeePerformanceChartData)
    console.log("员工评分雷达图=============================")
    console.log(employeeChartData)

  })
}
setInterval(getData, 3000)
</script>

<template>
</template>

<style scoped>

</style>